import cv2
#导入模型
face_cascade=cv2.CascadeClassifier("Train.xml")
#d读取图片

image=cv2.imread("3.png")
#灰度转换
gray=cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
#探测图片中的人脸
faces=face_cascade.detectMultiScale(
    gray,
    scaleFactor=1.15,
    minNeighbors=5,
    minSize=(5,5)
)

print("发现{0}个人脸".format(len(faces)))
for (x,y,w,h) in faces:
    cv2.rectangle(image, (x, y), (x + w, y + w), (0, 255, 0), 2)
cv2.imshow("fff",image)
cv2.waitKey(0)